/*************************************************************************************
CODED BY:                                                                            *
                                                                                     *
888888b.   8888888888        d8888 888b    888 8888888888P 8888888888 8888888b.      *
888  "88b  888              d88888 8888b   888       d88P  888        888   Y88b     *
888  .88P  888             d88P888 88888b  888      d88P   888        888    888     *
8888888K.  8888888        d88P 888 888Y88b 888     d88P    8888888    888   d88P     *
888  "Y88b 888           d88P  888 888 Y88b888    d88P     888        8888888P"      *
888    888 888          d88P   888 888  Y88888   d88P      888        888 T88b       *
888   d88P 888         d8888888888 888   Y8888  d88P       888        888  T88b      *
8888888P"  8888888888 d88P     888 888    Y888 d8888888888 8888888888 888   T88b     *
                                                                                     *
*************************************************************************************/


#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <unistd.h>
#include <cmath>
#include <cstdlib>
#include "CInitGL.h"
#include "CDrawGLScene.h"
#include "Cwindow.h"

///////////////////////////////////////////////////////////////////////////use pointers to acces the static data members
#define ESCAPE 27

using namespace std;

float depth = -10.0f,Movex = 0.0f, Movey = 0.0f, xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 0, angle=0.0, positionz[10], positionx[10];


void FancyRotate(void)

{

  glTranslatef(Movex,Movey,depth);		// Move Left 1.5 Units And Into The Screen 6.0

    glRotatef(xrot,1.0,0.0,0.0);
    glRotatef(yrot,0.0,1.0,0.0);
    glTranslated(-xpos,-ypos,-zpos);
    angle++;

}

 void Keyspecial(int key, int x, int y)
{

    if (key == GLUT_KEY_UP)
        {
            Movey += 0.5f;
            glutPostRedisplay();
        }
    if (key == GLUT_KEY_DOWN)
        {
            Movey += -0.5f;
            glutPostRedisplay();
        }
    if (key == GLUT_KEY_LEFT)
        {
            Movex += -0.5f;
            glutPostRedisplay();
        }
    if (key == GLUT_KEY_RIGHT)
        {
            Movex += 0.5f;
            glutPostRedisplay();
        }
    if (key == GLUT_KEY_PAGE_UP)
        {
            depth += 0.5f;
            glutPostRedisplay();
        }
    if (key == GLUT_KEY_PAGE_DOWN)
        {
            depth += -0.5f;
            glutPostRedisplay();
        }
}

 void Keyboard(unsigned char key, int x, int y)
{
//keyStates[key] = true;
  //  usleep(100);
    Cwindow wind;

    if (key == ESCAPE)
    {
      glutDestroyWindow(wind.foowindow);
      exit(0);
    }
     if (key=='q')
    {
    xrot += 1;
    if (xrot >360) xrot -= 360;
    }

    if (key=='e')
    {
    xrot -= 1;
    if (xrot < -360) xrot += 360;
    }

    if (key=='w')
    {
    float xrotrad, yrotrad;
    yrotrad = (yrot / 180 * 3.141592654f);
    xrotrad = (xrot / 180 * 3.141592654f);
    xpos += float(sin(yrotrad)) ;
    zpos -= float(cos(yrotrad)) ;
    ypos -= float(sin(xrotrad)) ;
    }

    if (key=='s')///////////////////////////////mess with this later
    {
    float xrotrad, yrotrad;
    yrotrad = (yrot / 180 * 3.141592654f);
    xrotrad = (xrot / 180 * 3.141592654f);
    xpos -= float(sin(yrotrad));
    zpos += float(cos(yrotrad)) ;
    ypos += float(sin(xrotrad));
    }

    if (key=='d')
    {
    yrot += 1;
    if (yrot >360) yrot -= 360;
    }

    if (key=='a')
    {
    yrot -= 1;
    if (yrot < -360)yrot += 360;
    }
}


int main(int argc, char **argv)
{
    CInitGL OInit;
    CDrawGLScene OScene;
    //CDrawGLScene::DrawGLScene();
    Cwindow wind;

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    glutInitWindowPosition(0, 0);
   wind.foowindow = glutCreateWindow("Sector7 beanzer Test");

    glutDisplayFunc(CDrawGLScene::DrawGLScenes);

  glutFullScreen();
  glutIdleFunc(CDrawGLScene::DrawGLScenes);
  glutReshapeFunc(CDrawGLScene::ReSizeGLScene);
  glutKeyboardFunc(Keyboard);
  //glutKeyboardUpFunc(CKeyboard::keyUp);
  glutSpecialFunc(Keyspecial);
  //glutKeyboardUpFunc(&specialKeyUp);
  OInit.InitGL(640, 480);
  glutMainLoop();

    return (0);
}

